import { defineMock } from "./base";

export default defineMock([
  {
    url: "dept/options",
    method: ["GET"],
    body: {
      code: "00000",
      data: [
        {
          value: '1',
          label: '四川',
          children: [
            {
              value: '2',
              label: '成都市',
            },
            {
              value: '3',
              label: '绵阳市',
            },
            {
              value: '4',
              label: '自贡市',
            },
            {
              value: '5',
              label: '攀枝花市',
            },
            {
              value: '6',
              label: '泸州市',
            },
            {
              value: '7',
              label: '德阳市',
            },
            {
              value: '8',
              label: '广元市',
            },
            {
              value: '9',
              label: '遂宁市',
            },
            {
              value: '10',
              label: '内江市',
            },
            {
              value: '11',
              label: '乐山市',
            },
            {
              value: '12',
              label: '资阳市',
            },
            {
              value: '13',
              label: '宜宾市',
            },
            {
              value: '14',
              label: '南充市',
            },
            {
              value: '15',
              label: '达州市',
            },
            {
              value: '16',
              label: '雅安市',
            },
            {
              value: '17',
              label: '广安市',
            },
            {
              value: '18',
              label: '巴中市',
            },
            {
              value: '19',
              label: '眉山市',
            },
            {
              value: '20',
              label: '阿坝藏族羌族自治州',
            },
            {
              value: '21',
              label: '甘孜藏族自治州',
            },
            {
              value: '22',
              label: '凉山彝族自治州',
            },
          ],
        },
      ],
      msg: "一切ok",
    },
  },

  {
    url: "dept",
    method: ["GET"],
    body: {
      code: "00000",
      data: [
        {
          id: 1,
          parentId: 0,
          name: "四川",
          code: "sc",
          sort: 1,
          status: 1,
          children: [
            {
              id: 2,
              parentId: 1,
              name: "成都市",
              code: "RD001",
              sort: 1,
              status: 1,
              children: [],
              createTime: null,
              updateTime: "2022-04-19 12:46",
            },
            {
              id: 3,
              parentId: 1,
              name: "绵阳市",
              code: "QA001",
              sort: 1,
              status: 1,
              children: [],
              createTime: null,
              updateTime: "2022-04-19 12:46",
            },
          ],
          createTime: null,
          updateTime: null,
        },
      ],
      msg: "一切ok",
    },
  },

  // 新增部门
  {
    url: "dept",
    method: ["POST"],
    body({ body }) {
      return {
        code: "00000",
        data: null,
        msg: "新增部门" + body.name + "成功",
      };
    },
  },

  // 获取部门表单数据
  {
    url: "dept/:id/form",
    method: ["GET"],
    body: ({ params }) => {
      return {
        code: "00000",
        data: deptMap[params.id],
        msg: "一切ok",
      };
    },
  },

  // 修改部门
  {
    url: "dept/:id",
    method: ["PUT"],
    body({ body }) {
      return {
        code: "00000",
        data: null,
        msg: "修改部门" + body.name + "成功",
      };
    },
  },

  // 删除部门
  {
    url: "dept/:id",
    method: ["DELETE"],
    body({ params }) {
      return {
        code: "00000",
        data: null,
        msg: "删除部门" + params.id + "成功",
      };
    },
  },
]);

// 部门映射表数据
const deptMap: Record<string, any> = {
  1: {
    id: 1,
    name: "有来技术",
    code: "YOULAI",
    parentId: 0,
    status: 1,
    sort: 1,
  },
  2: {
    id: 2,
    name: "研发部门",
    code: "RD001",
    parentId: 1,
    status: 1,
    sort: 1,
  },
  3: {
    id: 3,
    name: "测试部门",
    code: "QA001",
    parentId: 1,
    status: 1,
    sort: 1,
  },
};
